package cn.iocoder.yudao.module. enterprise.service.studentEducationalExperience;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module. enterprise.controller.admin.studentEducationalExperience.vo.*;
import cn.iocoder.yudao.module. enterprise.dal.dataobject.studentEducationalExperience.EnterpriseStudentEducationalExperienceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module. enterprise.convert.studentEducationalExperience.EnterpriseStudentEducationalExperienceConvert;
import cn.iocoder.yudao.module. enterprise.dal.mysql.studentEducationalExperience.EnterpriseStudentEducationalExperienceMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module. enterprise.enums.ErrorCodeConstants.*;

/**
 * 用户简历教育经历 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class EnterpriseStudentEducationalExperienceServiceImpl implements EnterpriseStudentEducationalExperienceService {

    @Resource
    private EnterpriseStudentEducationalExperienceMapper enterpriseStudentEducationalExperienceMapper;

    @Override
    public Long createEnterpriseStudentEducationalExperience(EnterpriseStudentEducationalExperienceCreateReqVO createReqVO) {
        // 插入
        EnterpriseStudentEducationalExperienceDO enterpriseStudentEducationalExperience = EnterpriseStudentEducationalExperienceConvert.INSTANCE.convert(createReqVO);
        enterpriseStudentEducationalExperienceMapper.insert(enterpriseStudentEducationalExperience);
        // 返回
        return enterpriseStudentEducationalExperience.getId();
    }

    @Override
    public void updateEnterpriseStudentEducationalExperience(EnterpriseStudentEducationalExperienceUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEnterpriseStudentEducationalExperienceExists(updateReqVO.getId());
        // 更新
        EnterpriseStudentEducationalExperienceDO updateObj = EnterpriseStudentEducationalExperienceConvert.INSTANCE.convert(updateReqVO);
        enterpriseStudentEducationalExperienceMapper.updateById(updateObj);
    }

    @Override
    public void deleteEnterpriseStudentEducationalExperience(Long id) {
        // 校验存在
        this.validateEnterpriseStudentEducationalExperienceExists(id);
        // 删除
        enterpriseStudentEducationalExperienceMapper.deleteById(id);
    }

    private void validateEnterpriseStudentEducationalExperienceExists(Long id) {
        if (enterpriseStudentEducationalExperienceMapper.selectById(id) == null) {
            throw exception(ENTERPRISE_STUDENT_EDUCATIONAL_EXPERIENCE_NOT_EXISTS);
        }
    }

    @Override
    public EnterpriseStudentEducationalExperienceDO getEnterpriseStudentEducationalExperience(Long id) {
        return enterpriseStudentEducationalExperienceMapper.selectById(id);
    }

    @Override
    public List<EnterpriseStudentEducationalExperienceDO> getEnterpriseStudentEducationalExperienceList(Collection<Long> ids) {
        return enterpriseStudentEducationalExperienceMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<EnterpriseStudentEducationalExperienceDO> getEnterpriseStudentEducationalExperiencePage(EnterpriseStudentEducationalExperiencePageReqVO pageReqVO) {
        return enterpriseStudentEducationalExperienceMapper.selectPage(pageReqVO);
    }

    @Override
    public List<EnterpriseStudentEducationalExperienceDO> getEnterpriseStudentEducationalExperienceList(EnterpriseStudentEducationalExperienceExportReqVO exportReqVO) {
        return enterpriseStudentEducationalExperienceMapper.selectList(exportReqVO);
    }

}
